package com.cdsf.common.conf;


import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

/**
 * @Author: kennedy
 * @Date: Created in 15:48 2018/2/6
 */
public class AbstractBase extends AssertContext{


    /**
     * 获取应用在服务器主机上的实际根目录
     *
     * @param request HttpServletRequest
     * @return String
     */
    public static String getWebRootPath(HttpServletRequest request) {
        return request.getSession().getServletContext().getRealPath("/");
    }

    protected String randomUUID() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    /**
     * <p>Description: 获取IP</p>
     *
     * @param request
     * @return
     * @author liushuai
     * @creaetime 2016年7月5日 下午7:34:44
     */
    public String getIpAddr(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }
}
